package com.infore.screw.core;

import com.infore.screw.core.engine.EngineConfig;
import com.infore.screw.core.engine.EngineFileType;
import com.infore.screw.core.engine.EngineTemplateType;
import com.infore.screw.core.execute.DocumentationExecute;
import com.infore.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class shouldAnswerWithTrue {

    @Test
    public void shouldAnswerWithTrue() {
        //数据源
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("oracle.jdbc.OracleDriver");
        hikariConfig.setJdbcUrl("jdbc:oracle:thin:@10.54.1.43:1521:helowin");
        hikariConfig.setUsername("QualityControl");
        hikariConfig.setPassword("QualityControl");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);

        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路径
                .fileOutputDir("D:\\Desktop")
                //打开目录
                .openOutputDir(true)
                //文件类型
                .fileType(EngineFileType.HTML)
                //生成模板实现
                .produceType(EngineTemplateType.freemarker)
                .fileName("文件名称")
                .build();

        //忽略表
        List<String> ignoreTableName = Arrays.asList("FIVE_PARAMETER_2022", "RECOVERY_1028", "RECOVERY_2022", "SPAN_DRIFT_1028", "SPAN_DRIFT_201102", "VERIFICATION_STA_SA1027_2", "VERIFICATION_STANDARD_SA_1027", "VERIFICATION_STANDARD_SA_1028", "VERIFICATION_STANDARD_SA_1106", "WEEK_QUALITY_CONTROL_201116", "ZERO_DRIFT_1028", "ZERO_DRIFT_201102");
        //忽略表前缀
        ArrayList<String> ignorePrefix = new ArrayList<>();
//        ignorePrefix.add("test_");
        //忽略表后缀
        ArrayList<String> ignoreSuffix = new ArrayList<>();
//        ignoreSuffix.add("_test");
        ProcessConfig processConfig = ProcessConfig.builder()
                //忽略表名
                .ignoreTableName(ignoreTableName)
                //忽略表前缀
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后缀
                .ignoreTableSuffix(ignoreSuffix).build();
        //配置
        Configuration config = Configuration.builder()
                //版本
                .version("1.0.0")
                //描述
                .description("数据库设计文档生成")
                //数据源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(engineConfig)
                //生成配置
                .produceConfig(processConfig).build();
        //执行生成
        new DocumentationExecute(config).execute();
    }
}
